angular.module('base.controllers', [])
.controller('CompanyCtrl', function($scope) {
	var companySubHandle = $scope.subscribe('companies');
	$scope.helpers({
		company: function() {
		  return Companies.findOne({}); 
		}
	});
	$scope.autorun(function(){
		if(companySubHandle.ready() && $scope.company){
			$scope.company.enabled_time = moment($scope.company.enabled_time).format('YYYY-MM-DD HH:mm:ss');
			$scope.company.expiration = moment($scope.company.expiration).format('YYYY-MM-DD HH:mm:ss');
			$scope.company.remaining = moment($scope.company.expiration).fromNow(true);
			
		}
	});
	$scope.update = function(){
		
		var theCompany = {
			_id:$scope.company._id,
			tel:$scope.company.tel,
			address:$scope.company.address
		};
		Meteor.call('updateCompanyInfo', theCompany, function(error){
			if (error) {
				console.log(error);
			} else {
				
			}
        });
	};
});
